package pkg

import (
	"fmt"
	"github.com/smartwalle/alipay/v3"
)

type AliPay struct {
	Subject     string
	OutTradeNo  string
	TotalAmount string
}

func (a *AliPay) Pay() string {
	var privateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC4fPHz0IUVF6RFEyTV6Z6PlgkwVpT+8d74P9BkYUJbqmrq1HZhVfOdkhf5DoWV2RqFpDSHqjQCNz204FEkbThGnxsrxZpcUuHimmkpKa2PV+MVX4XPjd1Rk+/0dw4IxMmoBLbcua19xS2O9OMGPd9K3Q6M57Cih8ICZSWOimHRdQnX+4grwuu1K4oilEAQ0olVbEE71+Z0cINrvOn5flCWsMEGUTdEtEMlK3ZwimoQK9+1JaEryK2C4lNi966EBxObgEB5UhxnwOCLXaomOUJXJhJYKJb/cqJeHbqL090gzb+RlmR/MBLb7fm/ELc9I9dHmBoRrE89gH45RgTNpMaNAgMBAAECggEAYUrzRoOXS5JWPV9lM7Kqvkp/uhBPL0xbLExrGCT6m+D51bIKZDax7U1Yey4fYPFHvWbllQ47s1dyoWsTH8TBwuyxpZnmV/4Vxi1sfBrQvyG4TlM7/ENyjk0YZLJMom81cfhaf3kkd4l/Bz86YtZKZe7Cd6jQTEaQGDdDYTK1d4H9dWBm8lllUE0nVfFjigFSiFJGQBsso8cKyDZ1NuXoLwpPA0PhwPzDVJ7CVaFiAcREygpZQukEQ9UAvozj71pSqAprP+K9xJjujGyidAY8eQCjo77NEmLmM+NZQRE9gPjhHwv9aqCxGsoso97Aft47axu1Cd1OhrQCR4TFcOtmwQKBgQDtq8sTxOxbXy35P0dLVjXQEXXoy7dxu47+h/AquLIiQ1kQJEGCYdIFPA6qizdHTwsre0FKqnR8Cz19Wdm85WSn34fm1Zyd3/wRRiR9epHMkw3VRI4MqKSSJ+ogZ5erAeGWbW6rPtMyVs9v4NzfE94TAorjsh7vGXXElWvsYDrKdQKBgQDGtzCOVdva2jOcJzec5sfyZAdNnvkHzYx7m2URhREaL7YZk5IEdd0wG8pVvJ46+0U+9OFOZIOAFCilepChQIyR92VP47/wz2ObVmJKomAgjAP/ei/jftjnHKpmzt+atKyIuK+98V+89J1OSTGEELDW/9yyEq4YwJO3pMcF0seYuQKBgGrzGoA75iw7yWFWs0tYcQC/SrLGMTdxsighndZrpGU8rzBPUFdOk4adfvAJk4d4L0uSvE/QInjLShFFRHD3PPM56FrclwyIBVL0oGkCpedL6TamEdHqdZv7cCTC2QIv54acmedfbwRBAjmTE3Ei7JTbWQqbVcY8S715i8Yji3EdAoGBAJHwSd3O2qdxJwQgnSxDJUc0BVURUq1TXUAOUPy78GJ99cv04AEcmrRRRJkQ7Fg+340sBSgwk48FvxBA4mU65cHxols41WdCuFGF8KwFcnmUuv7uuqrmJuAc4lycxAV3eVrz4EWsNnasY7bx9Each3Nu96NkKq4NCK+PeYciVOopAoGAEKS6zHxX+VAY66OPoh+gyydMe/BN10K1bf4+eryOUY8LZ3Lnd2hV95N6kSAboHSxTceXCMM3yOh02aHOpUuDSYKV/pvOc+wcy+9scHfoeBa5HAkQsSsJWz32qAh3wr+IlpCQ4A7+soEJPkFwpSCmse5K+Mn3MoftrKvez5plAx4=" // 必须，上一步中使用 RSA签名验签工具 生成的私钥
	var appId = "9021000143643557"
	client, err := alipay.New(appId, privateKey, false)
	if err != nil {
		fmt.Println(err)
		return ""
	}

	var p = alipay.TradeWapPay{}
	p.NotifyURL = "http://www.baidu.com"
	p.ReturnURL = "http://127.0.0.1"
	p.Subject = a.Subject
	p.OutTradeNo = a.OutTradeNo
	p.TotalAmount = a.TotalAmount
	p.ProductCode = "QUICK_WAP_WAY"

	url, err := client.TradeWapPay(p)
	if err != nil {
		fmt.Println(err)
	}

	// 这个 payURL 即是用于打开支付宝支付页面的 URL，可将输出的内容复制，到浏览器中访问该 URL 即可打开支付页面。
	var payURL = url.String()
	fmt.Println(payURL)
	return payURL
}
